import type { addressItem, addressParams } from '@/types/address'
import type { PageParams, PageResult } from '@/types/global'
import { request } from '@/utils/request'

/**
 * 添加地址
 * @param data
 * @returns
 */
export const postAddressApi = (data: addressParams) => {
  return request<addressItem>({
    method: 'POST',
    url: '/userAddress/add',
    data,
  })
}

export const getAddressApi = (data?: PageParams) => {
  return request<PageResult<addressItem>>({
    method: 'GET',
    url: '/userAddress',
    data,
  })
}

export const getAddressByIdApi = (id: string) => {
  return request<addressItem>({
    method: 'GET',
    url: `/userAddress/detail`,
    data: {
      id,
    },
  })
}

export const putAddressApi = (data: addressParams) => {
  return request<addressItem>({
    method: 'POST',
    url: `/userAddress/edit`,
    data,
  })
}

export const deleteAddressApi = (id: string | number) => {
  return request({
    method: 'POST',
    url: `/userAddress/delete`,
    data: {
      id,
    },
  })
}
